import React, {
  FC,
  // useState,
  useReducer,
} from "react";

type StateType = { count: number };
type ActionType = { type: string };
const initailState: StateType = { count: 100 };

function reducer(state: StateType, action: ActionType) {
  switch (action.type) {
    case "increment":
      return { count: state.count + 1 };
    case "decrement":
      return { count: state.count - 1 };
    default:
      throw new Error();
  }
}

const CountReducer: FC = () => {
  const [state, dispatch] = useReducer(reducer, initailState);
  // const [count, setCount] = useState(100)

  return (
    <>
      <span>count:{count}</span>
      <button onClick={() => setCount(count + 1)}>+</button>
      <button onClick={() => setCount(count - 1)}>-</button>
    </>
  );
};

export default CountReducer;
